<template>
  <div id="app">
    <h1>{{ msg }}</h1>

    <h3>拷贝对象,从存在的对象复制一个新对象出来</h3>

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="源桶">
        <el-input v-model="sourceBucketName" placeholder="源桶"></el-input>
      </el-form-item>
      <el-form-item label="源对象">
        <el-input v-model="sourceObjectName" placeholder="源对象"></el-input>
      </el-form-item>
    </el-form>

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="桶">
        <el-input v-model="bucketName" placeholder="桶"></el-input>
      </el-form-item>
      <el-form-item label="新对象">
        <el-input v-model="objectName" placeholder="新对象"></el-input>
      </el-form-item>
    </el-form>

    <p></p>
    <el-row>
      <el-button type="primary" @click="submit1()">拷贝对象</el-button>
    </el-row>

    <p>{{data}}</p>

  </div>
</template>

<script>


  var OSS = require("oss-js-client");

  // Instantiate the OSS client with the endpoint
  var ossClient = new OSS.Client({
    // endPoint: "192.168.1.40",
    endPoint: "127.0.0.1",
    port: 9000,
    useSSL: false,
    accessKey: "username",
    secretKey: "password",
  });

  export default {
    name: "VueOSSObjectCopy",
    data() {
      return {
        bucketName: "mybucket2",
        objectName: "b.txt",
        sourceBucketName: "mybucket2",
        sourceObjectName: "a.txt",
        data: '',
        formInline: {},
        msg: "演示OSSClient-Object Copy 对象拷贝",
      };
    },
    methods: {

      submit1: function () {
        //将源对象复制到指定存储桶中的新对象中
        let sourceObject = this.sourceBucketName + "/" + this.sourceObjectName;
        ossClient.copyObject(this.bucketName, this.objectName, sourceObject, null, (e, data) => {
          if (e) {
            this.data = data
            return console.log(e)
          }
          this.data = data
          console.log("Successfully copied the object:");
          console.log("etag = " + data.etag + ", lastModified = " + data.lastModified)
        });
      },

    },
  };
</script>

<style scope>
</style>
